using System.Configuration;
using System.Web.Configuration;

namespace $rootnamespace$
{
    /// <summary>
    /// A singleton class that manages the providers collection
    /// </summary>
    public class $safeitemname$
    {
        static $fileinputname$DataProviderManager()
        {
            Initialize();
        }

        private static $fileinputname$DataProvider _default;
        /// <summary>
        /// Returns the default configured data provider
        /// </summary>
        public static $fileinputname$DataProvider Default
        {
            get { return _default; }
        }

        private static $fileinputname$DataProviderCollection _providerCollection;
        /// <summary>
        /// .Returns the provider collection
        /// </summary>
        public static $fileinputname$DataProviderCollection Providers
        {
            get { return _providerCollection; }
        }

        private static ProviderSettingsCollection _providerSettings;
        public static ProviderSettingsCollection ProviderSettings
        {
            get { return _providerSettings; }
        }

        /// <summary>
        /// Reads the configuration related to the set of configured 
        /// providers and sets the default and collection of providers and settings.
        /// </summary>
        private static void Initialize()
        {
            $fileinputname$DataProviderConfiguration configSection = ($fileinputname$DataProviderConfiguration)ConfigurationManager.GetSection("$fileinputname$DataProvider");
            if (configSection == null)
                throw new ConfigurationErrorsException("Data provider section is not set.");

            _providerCollection = new $fileinputname$DataProviderCollection();
            ProvidersHelper.InstantiateProviders(configSection.Providers, _providerCollection, typeof($fileinputname$DataProvider));

            _providerSettings = configSection.Providers;

            if (_providerCollection[configSection.DefaultProviderName] == null)
                throw new ConfigurationErrorsException("Default data provider is not set.");
            _default = _providerCollection[configSection.DefaultProviderName];
        }
    }
}